package com.jh3502.vivo.function.tododetail.reim;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jh3502.vivo.base.BaseCallback;
import com.jh3502.vivo.base.BaseJson;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.base.BaseView;

import java.util.List;
import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class TodoReimPresenter extends BasePresenter<TodoReimPresenter.TodoReimView> {
    TodoReimModel mTodoReimModel;

    TodoReimView mTodoReimView;

    public void setTodoReimView(TodoReimView mTodoReimView) {
        this.mTodoReimView = mTodoReimView;
    }

    public void toGetExpenseById(Map<String, Object> body) {
        mTodoReimView.showLoadingDialog();
        if (mTodoReimModel == null) {
            mTodoReimModel = new TodoReimModel(mTodoReimView.getActContext());
        }

        mTodoReimModel.getExpenseById(body, new BaseCallback(mTodoReimView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {
                mTodoReimView.getExpenseByIdSuccess(new Gson().fromJson(baseJson.getObj().toString(), TodoReimBean.class));
            }
        });
    }

    public void toFindExpenseAudits(Map<String, Object> body) {
        mTodoReimView.showLoadingDialog();
        if (mTodoReimModel == null) {
            mTodoReimModel = new TodoReimModel(mTodoReimView.getActContext());
        }

        mTodoReimModel.findExpenseAudits(body, new BaseCallback(mTodoReimView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {
                List<TodoReimAuditsBean> list = new Gson().fromJson(baseJson.getObj().toString(),
                        new TypeToken<List<TodoReimAuditsBean>>() {
                        }.getType());
                mTodoReimView.findExpenseAuditsSuccess(list);
            }
        });

    }

    public void toAgreeForAll(List<Map<String, Object>> body) {
        mTodoReimView.showLoadingDialog();
        if (mTodoReimModel == null) {
            mTodoReimModel = new TodoReimModel(mTodoReimView.getActContext());
        }

        mTodoReimModel.agreeForAll(body, new BaseCallback(mTodoReimView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {

                mTodoReimView.agreeForAllSuccess();
            }
        });
    }

    public void toDeleteAudit(Map<String, Object> body) {
        mTodoReimView.showLoadingDialog();
        if (mTodoReimModel == null) {
            mTodoReimModel = new TodoReimModel(mTodoReimView.getActContext());
        }

        mTodoReimModel.deleteAudit(body, new BaseCallback(mTodoReimView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {

                mTodoReimView.deleteAuditSuccess();
            }
        });
    }

    public void toDeleteTask(Map<String, Object> body) {
        mTodoReimView.showLoadingDialog();
        if (mTodoReimModel == null) {
            mTodoReimModel = new TodoReimModel(mTodoReimView.getActContext());
        }

        mTodoReimModel.deleteTask(body, new BaseCallback(mTodoReimView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {

                mTodoReimView.deleteTaskSuccess();
            }
        });
    }

    @Override
    public void cancelCall() {

    }

    public interface TodoReimView extends BaseView {
        void getExpenseByIdSuccess(TodoReimBean todoReimBean);

        void findExpenseAuditsSuccess(List<TodoReimAuditsBean> list);

        void agreeForAllSuccess();

        void deleteAuditSuccess();

        void deleteTaskSuccess();
    }

}
